package com.cmd.driver;


import com.alibaba.fastjson.JSONObject;
import com.mgr.UserOrderMgr;
import com.player.DriverUser;
import com.player.User;
import com.qy.bean.OrderDriver;
import com.qy.bean.OrderInfo;
import com.qy.util.StaticData;
import com.util.AbstractCommand;
import com.util.PBMessage;

/**
 * 
 * 接受订单
 * @author zwl
 * 2018年2月1日
 */
public class OrderUploadImageCMD  extends AbstractCommand{

	@Override
	public void execute(User user, PBMessage packet) throws Exception {
		/*
		 * 1.判断司机之前的订单是否完成
		 * 2.接受订单
		 * 修改原来的订单状态为以接单
		 * 生成一条服务状态的服务订单
		 */
		JSONObject reJs = new JSONObject();
		reJs.put(StaticData.reKey.cmd.getKey(),packet.getCode());
		JSONObject param = packet.getMessage();
		if(!param.containsKey("imageO")||!param.containsKey("imageT")||!param.containsKey("imageTh")||
			!param.containsKey("imageF")||!param.containsKey("imageFi")||!param.containsKey("imageS")){
			reJs.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
			user.sendPacket(reJs);
			return;
		}
		DriverUser driverUser = (DriverUser) user;
		if(driverUser.getServerOrder()==null){
			reJs.put(StaticData.reKey.code.getKey(), StaticData.codeType.NOT_THIS_DRIVER.getType());
			user.sendPacket(reJs);
			return; 
		}
		/*
		 * 判断订单是否存在
		 */
		OrderDriver od = driverUser.getServerOrder();
		OrderInfo orderInfo = UserOrderMgr.getOrderInfo(od.getOrderId());
		if(orderInfo==null){
			reJs.put(StaticData.reKey.code.getKey(), StaticData.codeType.not_exist.getType());
			user.sendPacket(reJs);
			return; 
		}
		/*
		 * 更新图片
		 */
		String imageO = param.getString("imageO");
		String imageT = param.getString("imageT");
		String imageTh = param.getString("imageTh");
		String imageF = param.getString("imageF");
		String imageFi = param.getString("imageFi");
		String imageS = param.getString("imageS");
		od.setFImage(imageO);
		od.setSImage(imageT);
		od.setTImage(imageTh);
		od.setFoImage(imageF);
		od.setFiImage(imageFi);
		od.setSiImage(imageS);
//		od.setStatus(StaticData.DriverOrderStatus.START.getType());
		//扭转状态
		orderInfo.setOrderStatus(StaticData.OrderStatus.START_NOT_ARRIVE_STATION.getType());
		UserOrderMgr.update(orderInfo);
		reJs.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
		reJs.put(StaticData.reKey.cmd.getKey(),packet.getCode());
		user.sendPacket(reJs);
		return;
	}

}
